//index.js
//获取应用实例
const app = getApp()
var appData = app.globalData
Page({
    data: {
        flat_gl: true, //管理
        error_gl: true, //管理错误框
        error_gl_msg: "错误信息gl", //管理错误信息
        user_id: '',
        group_id: '',
        data: {
            id: '',
            notice: '欢迎来到挖钻天堂！',
            name: '',
            percent: ''
        }
    },
    onLoad: function (options) {
        let _this = this
        let user_id = options.user_id
        let group_id = options.group_id
        _this.setData({
            user_id: user_id,
            group_id: group_id
        })
        wx.request({
            url: appData.apiUrl + 'user/groupinfo',
            data: {
                user_id: user_id,
                group_id: group_id
            },
            success: function (res) {
                console.log('获取圈子信息')
                console.log(res)
                if (res.data.status == true) {
                    _this.setData({
                        data: res.data.data
                    })
                }
            }
        })
    },
    model_gl: function () {
        let _this = this;
        _this.setData({
            flat_gl: false
        })
    },
    close_gl: function () {
        this.setData({
            flat_gl: true
        })
    },
    // 表单提交:更新分红比例
    updateGroupPercent: function (e) {
        console.log('更新分红比例')
        let _this = this
        let percent = e.detail.value.percent
        let group_id = _this.data.group_id
        let reg = new RegExp("^(\\d|[1-9]\\d|100)$")
        if (!reg.test(e.detail.value.percent)) {
            wx.showModal({
                title: '提示',
                content: '请输入正确的分红比例(0-100正整数)',
                showCancel: false,
                success: function (res) {
                    if (res.confirm) {
                        return false
                        // console.log('用户点击确定')
                    }
                }
            })
        }else {
            wx.request({
                url: appData.apiUrl + 'user/updateinfo',
                data: {
                    group_id: group_id,
                    percent: percent
                },
                success: function (res) {
                    console.log(res)
                    if (res.data.status == true) {
                        _this.setData({
                            flat_gl: true,
                            data: res.data.data
                        })
                        wx.showToast({
                            title: '更新分成成功',
                            icon: 'success',
                            duration: 2000
                        })
                    }
                }
            })
        }
    },
    //退出圈子
    lingOut: function () {
        wx.showModal({
            title: '提示',
            content: '你当前还有2000.00投票未赎回，无法退出！请先将所有投票赎回再进行退圈操作。',
            showCancel: false,
            success: function (res) {
                if (res.confirm) {
                    // console.log('用户点击确定')
                }
            }
        })
    },
    //转让圈子
    lingTransfer: function () {
        wx.showModal({
            title: '提示',
            content: '确定转让圈子？',
            success: function (res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    //解散圈子
    lingDissolution: function () {
        wx.showModal({
            title: '提示',
            content: '确定解散圈子？',
            success: function (res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    //分享
    onShareAppMessage: function (res) {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log('分享')
            console.log(res.target)
        }
        return {
            title: '自定义转发标题',
            path: '/page/user?id=123'
        }
    },
    //跳转圈子二维码页
    goToCode: function () {
        let group_id = this.data.group_id
        let user_id = this.data.user_id
        wx.navigateTo({
            url: '../code/code?user_id=' + user_id + '&group_id=' + group_id
        })
    }
})